import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-03-08
 * Time: 12:14
 */
class Solution26 {
    public int compress(char[] chars) {
        List<String> lists = new ArrayList<>();
        int n = chars.length;
        for (int i = 0; i < n; ) {
            char key = chars[i];
            StringBuilder builder = new StringBuilder();
            for (int j = i; j < n; j++) {
                char tmp = chars[j];
                if (key == tmp) {
                    builder.append(tmp);
                } else {
                    i = j;
                    break;
                }
                // 如果 j 已经到达数组末尾，更新 i 到数组末尾之后的位置
                if (j == n - 1) {
                    i = j + 1;
                }
            }
            lists.add(builder.toString());
        }
        List<Character> ret = new ArrayList<>();
        for (String str : lists) {
            char firstChar = str.charAt(0);
            int len = str.length();
            ret.add(firstChar);
            char[] numsChar = getNumChar(len);
            if (numsChar.length == 1 && numsChar[0] == '1') {
                continue;
            } else {
                for (char x : numsChar) {
                    ret.add(x);
                }
            }
        }
        for(int i = 0 ; i < ret.size() ; i++){
            chars[i] = ret.get(i);
        }
        return ret.size();
    }

    public char[] getNumChar(int len) {
        StringBuilder builder = new StringBuilder();
        while (len != 0) {
            builder.append((char) ((len % 10) + '0'));
            len = len / 10;
        }
        String nums = builder.reverse().toString();
        return nums.toCharArray();
    }
}
public class Test26 {
    public static void main(String[] args) {
        Solution26 test = new Solution26();
        char[] chars = new char[]{'a','b','c'};
        test.compress(chars);
    }
}
